from pms.common.views import PostFormula
from project.utils.technology import project_update_technology
from project.models import Project
from technology.models import Technology
from project.utils.profile import technology_view
from project.utils.permission import assert_project_permissions


class API(PostFormula):
    def handle(self, req):
        tid = req['tid']
        pid = req['pid']
        mod = req['mod']
        assert_project_permissions(pid, self.user.id, [2])
        project, technology = project_update_technology(
            project=Project.objects.get(id=pid),
            technology=Technology.objects.get(id=tid),
            view=mod
        )
        return self.success_respond(technology_view(project, technology))
